package com.wn.ziroom.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wn.ziroom.entity.User;
import com.wn.ziroom.mapper.UserMapper;
import com.wn.ziroom.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wangzhijia
 * @since 2023-02-23 02:27:54
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    private UserMapper userMapper;
    @Autowired
    public void setUserMapper(UserMapper userMapper) {
        this.userMapper = userMapper;
    }


    @Override
    public void userRegister(User user) {
        userMapper.insert(user);
    }

    @Override
    public User selectByPhoneNumber(String userphone) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_phone",userphone);
         return userMapper.selectOne(queryWrapper);
    }

    @Override
    public User selectByUserName(String userName) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_username",userName);
        return userMapper.selectOne(queryWrapper);
    }

    @Override
    public User userByUser(User user) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_username",user.getUsername());
        queryWrapper.eq("user_password",user.getPassword());
        return userMapper.selectOne(queryWrapper);


    }

    @Override
    public void update(User user1) {

        userMapper.updateById(user1);
    }
}

